﻿using CrmField.Win8App.Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace CrmField.Win8App.Data
{
    [DataContract]
    public class ActivityDataGroup : BindableBase
    {
        private DateTime? _date = null;
        [DataMember]
        public DateTime? Date
        {
            get { return this._date; }
            set { this.SetProperty(ref this._date, value); }
        }

        private ObservableCollection<ServiceAppointment> _items;

        [DataMember]
        public ObservableCollection<ServiceAppointment> Items
        {
            get
            {
                if (_items == null)
                {
                    _items = new ObservableCollection<ServiceAppointment>();
                }
                return this._items;
            }
        }

        [IgnoreDataMember]
        public String FormatedDate
        {
            get
            {
                return (Date.HasValue ? Date.Value.ToString("dddd d MMM") : string.Empty); // Sunday 6 Jan
            }
        }

        [IgnoreDataMember]
        public ObservableCollection<ServiceAppointment> TopItems
        {
            get
            {
                return new ObservableCollection<ServiceAppointment>(this.Items.Take((Items.Count >= 12 ? 12 : Items.Count)));
            }
        }

        public ActivityDataGroup(DateTime date)
        {
            this._date = date;
        }
    }
}
